/*
 * ViewUtils.cpp
 *
 *  Created on: 22/05/2014
 *      Author: lucio
 */

#include "ViewUtils.h"

namespace Utils {
	SDL_Surface* LoadImage(std::string filename) {
		SDL_Surface* loadedImage = NULL;
		SDL_Surface* optimizedImage = NULL;

		loadedImage = IMG_Load(filename.c_str());

		if(loadedImage != NULL) {
			optimizedImage = SDL_DisplayFormat(loadedImage);
			SDL_FreeSurface(loadedImage);

			if(optimizedImage != NULL) {
				SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY,
						SDL_MapRGB(optimizedImage->format, 0, 0xFF, 0xFF));
			}
		}

		return optimizedImage;
	}

	void ApplySurface(int x, int y, SDL_Surface* source,
			SDL_Surface* destination, SDL_Rect* clip = NULL) {
		//Holds offsets
		SDL_Rect offset;

		//Get offsets
		offset.x = x;
		offset.y = y;

		//Blit
		SDL_BlitSurface(source, clip, destination, &offset);
	}
}

